﻿using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ZhuXingFamilys.Help;

namespace ZhuXingFamilys.MainFamilyView
{
    /// <summary>
    /// LoadFamilyProperty.xaml 的交互逻辑
    /// </summary>
    public partial class LoadFamilyProperty : Window
    {
        LoadFamily loadFamily = null;
        ExternalEvent LoadFamilyEvent = null;

        private string familyFileName;
        private string loadButtonCont;
        private string familyFileCategory;
        private string familyCategoryName;
        private string familyNodeID;
        bool minimize = false;
        public LoadFamilyProperty(LoadFamily loadFamily, ExternalEvent loadFamilyEvent, string familyFileName, string loadButtonCont, string familyFileCategory, string familyCategoryName, string familyNodeID)
        {
            InitializeComponent();
            this.loadFamily = loadFamily;
            this.LoadFamilyEvent = loadFamilyEvent;
            this.familyFileName = familyFileName;
            this.loadButtonCont = loadButtonCont;
            this.familyFileCategory = familyFileCategory;
            this.familyCategoryName = familyCategoryName;
            this.familyNodeID = familyNodeID;

            // 获取当前族文件可配置参数


            this.Closed += LoadFamilyProperty_Closed;
        }
        // 窗口关闭事件
        private void LoadFamilyProperty_Closed(object sender, EventArgs e)
        {
            // 判断MainFamilyView是否需要最小化
            if (minimize)
            {
                MainFamilyView mv = MainFamilyView.GetInstance();
                mv.WindowState = WindowState.Minimized;
            }
        }

        // 按钮
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;
            if (b.Content.ToString() == "确定")
            {
                loadFamily.FamilyFileName = familyFileName;
                loadFamily.LoadButtonCont = loadButtonCont;
                loadFamily.FamilyFileCategory = familyFileCategory;
                loadFamily.FamilyCategoryName = familyCategoryName;
                loadFamily.FamilyNodeID = familyNodeID;
                LoadFamilyEvent.Raise();
                minimize = true;
                this.Close();
            }
            if (b.Content.ToString() == "取消")
            {
                this.Close();
            }

        }
        // 加载完成
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                string FileAddress = Set.settingaddress("Setup.ini");
                var img = new BitmapImage();
                img.BeginInit();
                string Path = FileAddress;
                string ImageFullPath = Path + "\\" + familyNodeID + "\\" + familyFileName + ".png";
                img.StreamSource = new MemoryStream(File.ReadAllBytes(ImageFullPath));
                img.EndInit();
                FamilyImg.Source = img;
                this.FamilyName.Text = familyCategoryName;
                this.FamilyNumber.Text = "105020010010001";
            }
            catch (Exception)
            {
                FamilyImg.Source = CsAddpanel.convertFromBitmap(Properties.Resource.公共族库);
            }

            this.HNTZL.ItemsSource = new List<string>()
            {
                "预拌"
            };
            this.QDDJ.ItemsSource = new List<string>()
            {
                "C20",
                "C25",
                "C30",
                "C35"
            };
            this.JMCC.ItemsSource = new List<string>()
            {
                "200*200",
                "200*250",
                "200*300"
            };
        }
    }
}
